Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Pull Request — master (#947)
by
unknown
03:53
created

smr15.js ➔ graph_by_plotly   B

Complexity

Conditions 1

Size

Total Lines 47
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 37
dl 0
loc 47
rs 8.9919
c 0
b 0
f 0
1
(function() {
2
"use strict";
3
4
	window.voteSite = function(snUrl) {
5
		// Must not redirect the current page until after the external vote
6
		// site URL has been opened in a new tab. Use setTimeout to do this.
7
		setTimeout(function() {
8
			window.location = snUrl;
9
		}, 0);
10
	};
11
12
	function doCalc(type, number, totalDest) {
13
		var i = 1, total = 0, df=document.FORM;
14
		for(; i<=number; i++) {
15
			total += df[type+i].value * 1;
16
		}
17
		df[totalDest].value = total;
18
	};
19
20
	// Recalculate total number of ports, summing over level
21
	window.levelCalc = function(maxPortLevel) {
22
		doCalc('port', maxPortLevel, 'total');
23
	};
24
25
	// Recalculate sum of port race percentages
26
	window.raceCalc = function() {
27
		doCalc('race', 9, 'racedist');
28
	};
29
30
	// Set the total number of ports to zero
31
	window.setZero = function(maxPortLevel) {
32
		var df = document.FORM;
33
		for (var i=1; i<=maxPortLevel; i++) {
34
			df['port'+i].value = 0;
35
		}
36
		df.total.value = 0;
37
	};
38
39
	// Set the port race distribution to be equal
40
	window.setEven = function() {
41
		var i = 2, df=document.FORM;
42
		df.race1.value = 12;
43
		for(; i<=9; i++) {
44
			df['race'+i].value = 11;
45
		}
46
		df.racedist.value = 100;
47
	};
48
49
	var body, currentlyFlashing=false, flashColour, origColour, intervalFlash, timeoutStopFlash;
50
51
	function stopFlash() {
52
		clearInterval(intervalFlash);
53
		body.style.backgroundColor = origColour;
0 ignored issues
show
Bug introduced by
The variable body seems to be never initialized.
Loading history...
54
		currentlyFlashing = false;
55
	};
56
57
	function bgFlash() {
58
		var body = document.getElementsByTagName('body')[0];
59
		if(body.style.backgroundColor === origColour) {
60
			body.style.backgroundColor = flashColour;
61
		}
62
		else {
63
			body.style.backgroundColor = origColour;
64
		}
65
	};
66
67
	window.triggerAttackBlink = function(colour) {
68
		if(origColour == null) {
0 ignored issues
show
Best Practice introduced by
Comparing origColour to null using the == operator is not safe. Consider using === instead.
Loading history...
69
			origColour = document.getElementsByTagName('body')[0].style.backgroundColor;
70
		}
71
		flashColour = '#'+colour;
72
		clearTimeout(timeoutStopFlash);
73
		if (currentlyFlashing === false) {
74
			currentlyFlashing = true;
75
			//flash 3 times
76
			bgFlash();
77
			intervalFlash = setInterval(bgFlash,500);
78
		}
79
		timeoutStopFlash = setTimeout(stopFlash,3500);
80
	};
81
})();
82
83
// Used by shop_hardware.php
84
function recalcOnKeyUp(transaction, hardwareTypeID, cost) {
85
	var form = document.getElementById(transaction + hardwareTypeID);
86
	form.total.value = form.amount.value * cost;
87
}
88
89
// Used by planet_defense.php
90
function showWeaponInfo(select) {
91
	var target = $(select).data('target');
92
	var show = $("option:selected", select).data('show');
93
	$(target).children().addClass('hide');
94
	$(show).removeClass('hide');
95
}
96
97
// Used by game_join.php
98
function showRaceInfo(select) {
99
	var race_id = $("option:selected", select).val();
100
	document.getElementById('race_image').src = "images/race/race" + race_id + ".jpg";
101
	document.getElementById('graphframe').src = "images/race/graph/graph" + race_id + ".gif";
102
	var desc = document.getElementById('race_descr');
103
	$(desc).children().addClass('hide');
104
	$(".race_descr" + race_id, desc).removeClass('hide');
105
	graph_by_plotly(race_id);
106
}
107
108
// Used by game_join.php 
109
function graph_by_plotly(race_id) {
110
111
	var races = [["[1.0,1.0,1.0,1.0,1.0]","'Neutral'","'#FFD800'"],
112
	[[1.0,1.0,1.0,1.0,1.0],'Neutral','#FFD800'],
113
	[[5.2, 10.0, 5.8, 8.1, 5.2],'Alaskant','#FF00FF'],
114
	[[8.3, 5.0, 10.0, 3.3, 8.3],'Creonti','#FF8000'],
115
	[[9.5, 4.9, 9.5, 7.7, 9.5],'Human','#0000FF'],
116
	[[8.0, 6.1, 9.7, 10.0, 8.0],'Ik\'Thorne','#BFBFFF'],
117
	[[8.1, 4.7, 8.8, 4.3, 8.1],'Salvene','#00AA00'],
118
	[[10.0, 5.7, 8.7, 9.1, 10.0],'Thevian','#800000'],
119
	[[7.2, 6.3, 7.9, 6.2, 7.2],'WQ Human','#804040'],
120
	[[9.5, 4.9, 8.0, 5.1, 9.5],'Nijarin','#FF8080']];
121
	data = [
0 ignored issues
show
Bug introduced by
The variable data seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.data.
Loading history...
122
		{
123
			type: 'scatterpolar',
124
			r: races[race_id][0],
125
			theta: ['Hunting','Trading','Combat', 'Utility', 'Hunting'],
126
			fill: 'toself',
127
			name: races[race_id][1],
128
			line: {color: races[race_id][2], dash: 'longdash'},
129
			title: {
130
				text: races[race_id][1]
131
			}
132
		}
133
	];
134
135
	layout = {
0 ignored issues
show
Bug introduced by
The variable layout seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.layout.
Loading history...
136
		showlegend: true,
137
		polar: {
138
			radialaxis: {
139
				visible: true,
140
				showgrid: true,
141
				range: [0, 11],
142
				color: '#000',
143
				plot_bgcolor: '#000',
144
				bgcolor: '#000',
145
			},
146
		},
147
		paper_bgcolor: '#06240E',
148
		plot_bgcolor: '#000',
149
		font: {
150
			color: '#fff'
151
		},
152
		coloraxis : '#000'
153
	};
154
	Plotly.newPlot("graphframe", data, layout, {staticPlot: true});
0 ignored issues
show
Bug introduced by
The variable Plotly seems to be never declared. If this is a global, consider adding a /** global: Plotly */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
155
}
156
// Used by alliance_create.php and alliance_stat.php
157
function togglePassword(select) {
158
	var showPassword = $(select).val() === "password";
159
	// We need to both toggle the element display (for the user) and toggle the
160
	// disabled property (for the form submission).
161
	if (showPassword) {
162
		$("#password-display").show();
163
	} else {
164
		$("#password-display").hide();
165
	}
166
	$("#password-input").prop("disabled", !showPassword);
167
}
168